package com.roy.reversi.controller;

import java.awt.Dimension;
import java.awt.Graphics;

import com.roy.reversi.ai.PCThread;
import com.roy.reversi.listener.IReversiListener;
import com.roy.reversi.model.Chessboard;
import com.roy.reversi.view.ControlPanel;
import com.roy.reversi.view.GamePanel;

public class Controller implements IReversiListener{

	private GamePanel gamePanel;
	private ControlPanel controlPanel;
	private Chessboard chessboard;
	
	public Controller(){
		chessboard = new Chessboard();
		chessboard.addListener(this);
		PCThread pt = new PCThread(chessboard);
		pt.start();
	}
	
	public GamePanel getGamePanel() {
		return gamePanel;
	}
	public void setGamePanel(GamePanel gamePanel) {
		this.gamePanel = gamePanel;
	}
	public ControlPanel getControlPanel() {
		return controlPanel;
	}
	public void setControlPanel(ControlPanel controlPanel) {
		this.controlPanel = controlPanel;
	}
	public Chessboard getChessboard() {
		return chessboard;
	}
	public void setChessboard(Chessboard chessboard) {
		this.chessboard = chessboard;
	}
	
	public void newGame(){
		chessboard.newGame();
		gamePanel.getContailPanel().repaint();
		controlPanel.setInfo();
	}
	
	public void put(int color, int x, int y){
		chessboard.put(color, x, y); 
	}
	
	@Override
	public void put() {
		gamePanel.repaint();
		controlPanel.setInfo();
	}
	
	public void draw(Graphics g){
		chessboard.draw(g);
	}
	
	public Dimension getGamePanelDimension(){
		return new Dimension(Chessboard.TOTAL_WIDTH, Chessboard.TOTAL_HEIGHT);
	}
	
	public int getWhiteNum(){
		return chessboard.getWhiteNum();
	}
	
	public int getBlackNum(){
		return chessboard.getBlackNum();
	}
	
	public String getCurPlayer(){
		return chessboard.getCurPlayer();
	}

	@Override
	public void setInfo(String info) {
		gamePanel.setInfo(info);
	}
	
}
